package model;

/**
 * @author Darko Martinovikj
 * @version 1.0 13.03.2013
 * 
 * Class representing a hash table for storing all the transitions' restrictions for program graphs 
 *  *  
 *  */
import java.util.HashMap;
import java.util.LinkedList;

/** Class for storing all the restrictions for every transition
 * @author DarkoLaptop2
 *
 */
public class TransitionRestrictionHashTable {

	private HashMap<String, LinkedList<String>> table;

	/**
	 * Constructor of the class. Creates a new hash table
	 * 
	 */
	public TransitionRestrictionHashTable() {
		table = new HashMap<String, LinkedList<String>>();
	}

	/**
	 * Method for transition restriction insertion. The transition name and the restriction must be specified
	 * 
	 * @param String  transitionName - name of the transition
	 * @param String restrictionString - the restriction string
	 */
	public void insertTransition(String transitionName, String restrictionString) {
		LinkedList<String> restrictionsList=table.get(transitionName);
		if (restrictionsList==null)
			restrictionsList=new LinkedList<String>();
		restrictionsList.addLast(restrictionString);
		table.put(transitionName, restrictionsList);
	}

	/**
	 * Method for transition deletion. The transition name must be specified
	 * 
	 * @param String transitionName - name of the transition which will be deleted
	 */
	public void removeTransition(String transitionName) {
		table.remove(transitionName);
	}

	/**
	 * Method for returning all of the restrictions of a given transition 
	 * @param transitionName
	 * @return LinkedList<String> - List of restriction names for the transition
	 */
	public LinkedList<String> getTransitionRestrictions(String transitionName) {
		LinkedList<String> allRestrictions = new LinkedList<String>();
		LinkedList<String> restrictions=table.get(transitionName);
		if(restrictions!=null)
			for(String restriction:restrictions)
				allRestrictions.add(restriction);
		return allRestrictions;
	}
	
	/**
	 * Method for returning the string for all of the transitions and their type
	 * @return - String - for printing
	 * */
	public String toString()
	{
		String s="";
		for(String element:table.keySet())
			s+="Transition: "+element+" value: "+getTransitionRestrictions(element).toString()+" \n";
		return s;
	}

}
